package com.vanysoft.business.base.tag.controller;

import com.vanysoft.business.base.tag.service.BaseTagService;
import com.vanysoft.business.sys.entity.UserInfo;
import com.vanysoft.framework.base.action.BaseController;
import com.vanysoft.framework.config.mvc.SessionUser;
import com.vanysoft.framework.exception.VanySoftBaseException;
import com.vanysoft.framework.utils.JSONResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 项目名称：SharpClaw移动门户
 * 类名称：BaseTagController
 * 类描述：用户分类
 * 创建人：SharpClaw_x
 * 创建时间：2017年5月26日 上午9:48:49
 * 修改人：SharpClaw_x
 * 修改时间：2017年5月26日 上午9:48:49
 * 版本信息：@version 1.0
 * Copyright (c) 2017SharpClaw-版权所有
 * 修改备注：
 */
@RestController
@RequestMapping("/base/tag")
public class BaseTagController extends BaseController {

    @Autowired
    private BaseTagService baseTagService;

    /**
     * Function Name               loadTag
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 加载用户分类
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 上午10:07:59           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/loadTag", method = {RequestMethod.GET})
    public JSONResponse loadTag(@SessionUser UserInfo userInfo, HttpServletRequest request) throws VanySoftBaseException {
        String tagType = request.getParameter("tagType");
        List<Map> resultList = baseTagService.loadTag(tagType, userInfo.getId());
        return new JSONResponse(resultList);

    }

    /**
     * Function Name               queryTagUser
     *
     * @param request
     * @return
     * @description 查询分类人员
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 上午11:36:48           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/queryTagUser", method = {RequestMethod.GET})
    public JSONResponse queryTagUser(HttpServletRequest request) {
        String tagCode = request.getParameter("tagCode");
        String searchContent = request.getParameter("searchContent");
        String pageIndex = request.getParameter("pageIndex");
        if (StringUtils.isEmpty(pageIndex)) {
            pageIndex = "1";
        }
        String pageSize = request.getParameter("pageSize");
        if (StringUtils.isEmpty(pageSize)) {
            pageSize = "10";
        }
        Map result = baseTagService.queryTagUser(tagCode, Integer.parseInt(pageIndex), Integer.parseInt(pageSize), searchContent);
        return new JSONResponse(result);

    }

    /**
     * Function Name               selectTagUser
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 选择分类人员
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 下午5:49:47           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/selectTagUser", method = {RequestMethod.POST})
    public JSONResponse selectTagUser(HttpServletRequest request) throws VanySoftBaseException {
        String tagCode = request.getParameter("tagCode");
        String userIdStr = request.getParameter("userIdStr");
        baseTagService.selectTagUser(tagCode, userIdStr);
        return new JSONResponse();

    }

    /**
     * Function Name               addTag
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 我的分类和外部人员添加分类
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 下午6:13:44           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/addTag", method = {RequestMethod.POST})
    public JSONResponse addTag(@SessionUser UserInfo userInfo, HttpServletRequest request) throws VanySoftBaseException {
        String parentTagCode = request.getParameter("parentTagCode");
        String tagType = request.getParameter("tagType");
        String tagName = request.getParameter("tagName");
        Map tagMap = baseTagService.addTag(tagType, tagName, parentTagCode, userInfo.getId());
        return new JSONResponse(tagMap);

    }

    /**
     * Function Name               modifyTag
     *
     * @param request
     * @return
     * @description 修改分类
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 下午6:27:16           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/modifyTag", method = {RequestMethod.POST})
    public JSONResponse modifyTag(HttpServletRequest request) {
        String tagCode = request.getParameter("tagCode");
        String tagName = request.getParameter("tagName");
        baseTagService.modifyTag(tagCode, tagName);
        return new JSONResponse();

    }

    /**
     * Function Name               deleteTag
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 删除分类
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 下午6:31:35           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/deleteTag", method = {RequestMethod.POST})
    public JSONResponse deleteTag(HttpServletRequest request) throws VanySoftBaseException {
        String tagCode = request.getParameter("tagCode");
        baseTagService.deleteTag(tagCode);
        return new JSONResponse();

    }

    /**
     * Function Name               addBaseTag
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 公共分类添加
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月27日 上午9:29:37           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/addBaseTag", method = {RequestMethod.POST})
    public JSONResponse addBaseTag(@SessionUser UserInfo userInfo, HttpServletRequest request) throws VanySoftBaseException {
        String parentTagCode = request.getParameter("parentTagCode");
        String tagType = request.getParameter("tagType");
        String tagName = request.getParameter("tagName");
        Map tagMap = baseTagService.addTag(tagType, tagName, parentTagCode, userInfo.getId());
        return new JSONResponse(tagMap);

    }

    /**
     * Function Name               modifyTag
     *
     * @param request
     * @return
     * @description 修改公共分类
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 下午6:27:16           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/modifyBaseTag", method = {RequestMethod.POST})
    public JSONResponse modifyBaseTag(HttpServletRequest request) {
        String tagCode = request.getParameter("tagCode");
        String tagName = request.getParameter("tagName");
        baseTagService.modifyTag(tagCode, tagName);
        return new JSONResponse();

    }

    /**
     * Function Name               deleteTag
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 删除公共分类
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年5月26日 下午6:31:35           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/deleteBaseTag", method = {RequestMethod.POST})
    public JSONResponse deleteBaseTag(HttpServletRequest request) throws VanySoftBaseException {
        String tagCode = request.getParameter("tagCode");
        baseTagService.deleteTag(tagCode);
        return new JSONResponse();

    }

    /**
     * Function Name               deleteTagUser
     *
     * @param request
     * @return
     * @throws VanySoftBaseException
     * @description 批量删除人员
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年6月19日 上午11:56:32           SharpClaw_x                    Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/deleteTagUser", method = {RequestMethod.POST})
    public JSONResponse deleteTagUser(HttpServletRequest request) throws VanySoftBaseException {
        String tagCode = request.getParameter("tagCode");
        String userIds = request.getParameter("userIds");
        baseTagService.deleteTagUser(tagCode, userIds);
        return new JSONResponse();

    }
}
